package com.wn.network.repository

import com.wn.network.flow.getStateFlow
import com.wn.network.response.BaseResponse
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.StateFlow

/**
 * @Author: wn
 * @Date: 2024/8/8 16:29
 * @Description: 基础仓库 -- 获取 StateFlow
 */
open class BaseRepository {
  /**
   * BaseRepository 中  获取 StateFlow<T?>
   * @param scope CoroutineScope
   * @param errorCall Function2<Int?, String?, Unit>?
   * @param showLoading Function1<Boolean, Unit>?
   * @param requestCall SuspendFunction0<BaseResponse<T>?>
   * @return StateFlow<T?>
   */
  protected fun <T> callStateFlow(
    scope: CoroutineScope,
    errorCall: ((Int?, String?) -> Unit)? = null,
    showLoading: ((Boolean) -> Unit)? = null,
    requestCall: suspend () -> BaseResponse<T>?,
  ): StateFlow<T?> = getStateFlow(scope, errorCall, showLoading, requestCall)
}